<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="员工ID" prop="staffId">
        <el-input
          v-model="queryParams.staffId"
          placeholder="请输入员工ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="药品数量" prop="medicineAmount">
        <el-input
          v-model="queryParams.medicineAmount"
          placeholder="请输入药品数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="草药数量" prop="herbalAmount">
        <el-input
          v-model="queryParams.herbalAmount"
          placeholder="请输入草药数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检查数量" prop="checkAmount">
        <el-input
          v-model="queryParams.checkAmount"
          placeholder="请输入检查数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处置数量" prop="dispositionAmount">
        <el-input
          v-model="queryParams.dispositionAmount"
          placeholder="请输入处置数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="挂号数量" prop="registrationAmount">
        <el-input
          v-model="queryParams.registrationAmount"
          placeholder="请输入挂号数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检验数量" prop="testAmount">
        <el-input
          v-model="queryParams.testAmount"
          placeholder="请输入检验数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总量" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入总量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期" prop="date">
        <el-date-picker clearable
          v-model="queryParams.date"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="挂号人数" prop="registrationNum">
        <el-input
          v-model="queryParams.registrationNum"
          placeholder="请输入挂号人数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="执行检查数量" prop="excuteCheckAmount">
        <el-input
          v-model="queryParams.excuteCheckAmount"
          placeholder="请输入执行检查数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="执行检验数量" prop="excuteTestAmount">
        <el-input
          v-model="queryParams.excuteTestAmount"
          placeholder="请输入执行检验数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="执行处置数量" prop="excuteDispositionAmount">
        <el-input
          v-model="queryParams.excuteDispositionAmount"
          placeholder="请输入执行处置数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科室ID" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入科室ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="执行数量" prop="excuteNum">
        <el-input
          v-model="queryParams.excuteNum"
          placeholder="请输入执行数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['sms:workloadRecord:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['sms:workloadRecord:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['sms:workloadRecord:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['sms:workloadRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="workloadRecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="员工ID" align="center" prop="staffId" />
      <el-table-column label="药品数量" align="center" prop="medicineAmount" />
      <el-table-column label="草药数量" align="center" prop="herbalAmount" />
      <el-table-column label="检查数量" align="center" prop="checkAmount" />
      <el-table-column label="处置数量" align="center" prop="dispositionAmount" />
      <el-table-column label="挂号数量" align="center" prop="registrationAmount" />
      <el-table-column label="检验数量" align="center" prop="testAmount" />
      <el-table-column label="总量" align="center" prop="amount" />
      <el-table-column label="日期" align="center" prop="date" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="挂号人数" align="center" prop="registrationNum" />
      <el-table-column label="执行检查数量" align="center" prop="excuteCheckAmount" />
      <el-table-column label="执行检验数量" align="center" prop="excuteTestAmount" />
      <el-table-column label="执行处置数量" align="center" prop="excuteDispositionAmount" />
      <el-table-column label="类型" align="center" prop="type" />
      <el-table-column label="科室ID" align="center" prop="deptId" />
      <el-table-column label="执行数量" align="center" prop="excuteNum" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['sms:workloadRecord:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['sms:workloadRecord:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改门诊医生、科室工作量统计对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="员工ID" prop="staffId">
          <el-input v-model="form.staffId" placeholder="请输入员工ID" />
        </el-form-item>
        <el-form-item label="药品数量" prop="medicineAmount">
          <el-input v-model="form.medicineAmount" placeholder="请输入药品数量" />
        </el-form-item>
        <el-form-item label="草药数量" prop="herbalAmount">
          <el-input v-model="form.herbalAmount" placeholder="请输入草药数量" />
        </el-form-item>
        <el-form-item label="检查数量" prop="checkAmount">
          <el-input v-model="form.checkAmount" placeholder="请输入检查数量" />
        </el-form-item>
        <el-form-item label="处置数量" prop="dispositionAmount">
          <el-input v-model="form.dispositionAmount" placeholder="请输入处置数量" />
        </el-form-item>
        <el-form-item label="挂号数量" prop="registrationAmount">
          <el-input v-model="form.registrationAmount" placeholder="请输入挂号数量" />
        </el-form-item>
        <el-form-item label="检验数量" prop="testAmount">
          <el-input v-model="form.testAmount" placeholder="请输入检验数量" />
        </el-form-item>
        <el-form-item label="总量" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入总量" />
        </el-form-item>
        <el-form-item label="日期" prop="date">
          <el-date-picker clearable
            v-model="form.date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="挂号人数" prop="registrationNum">
          <el-input v-model="form.registrationNum" placeholder="请输入挂号人数" />
        </el-form-item>
        <el-form-item label="执行检查数量" prop="excuteCheckAmount">
          <el-input v-model="form.excuteCheckAmount" placeholder="请输入执行检查数量" />
        </el-form-item>
        <el-form-item label="执行检验数量" prop="excuteTestAmount">
          <el-input v-model="form.excuteTestAmount" placeholder="请输入执行检验数量" />
        </el-form-item>
        <el-form-item label="执行处置数量" prop="excuteDispositionAmount">
          <el-input v-model="form.excuteDispositionAmount" placeholder="请输入执行处置数量" />
        </el-form-item>
        <el-form-item label="科室ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入科室ID" />
        </el-form-item>
        <el-form-item label="执行数量" prop="excuteNum">
          <el-input v-model="form.excuteNum" placeholder="请输入执行数量" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWorkloadRecord, getWorkloadRecord, delWorkloadRecord, addWorkloadRecord, updateWorkloadRecord } from "@/api/sms/workloadRecord";

export default {
  name: "WorkloadRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 门诊医生、科室工作量统计表格数据
      workloadRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        staffId: null,
        medicineAmount: null,
        herbalAmount: null,
        checkAmount: null,
        dispositionAmount: null,
        registrationAmount: null,
        testAmount: null,
        amount: null,
        date: null,
        status: null,
        registrationNum: null,
        excuteCheckAmount: null,
        excuteTestAmount: null,
        excuteDispositionAmount: null,
        type: null,
        deptId: null,
        excuteNum: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询门诊医生、科室工作量统计列表 */
    getList() {
      this.loading = true;
      listWorkloadRecord(this.queryParams).then(response => {
        this.workloadRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createTime: null,
        staffId: null,
        medicineAmount: null,
        herbalAmount: null,
        checkAmount: null,
        dispositionAmount: null,
        registrationAmount: null,
        testAmount: null,
        amount: null,
        date: null,
        status: null,
        registrationNum: null,
        excuteCheckAmount: null,
        excuteTestAmount: null,
        excuteDispositionAmount: null,
        type: null,
        deptId: null,
        excuteNum: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加门诊医生、科室工作量统计";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getWorkloadRecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改门诊医生、科室工作量统计";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWorkloadRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWorkloadRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除门诊医生、科室工作量统计编号为"' + ids + '"的数据项？').then(function() {
        return delWorkloadRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('sms/workloadRecord/export', {
        ...this.queryParams
      }, `workloadRecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
